/**
* 
* ====================================================================
*
* @author apov <apov@ymail.com>
*/ 
#pragma once

#include "DBSession.h"
#include <mysql.h>
#include "MySQL_DBError.h"

/**
* @class MySQL_DBSession
*  - 
*/ 
class MySQL_DBStatement;
class MySQL_DBSession : public DBSession{
	enum{
		DEF_DEFAULT_PORT=				3306,
		DEF_CONNECTION_STRING_SIZE=		1024,
		
		DEF_DROP_COUNT=					10,		
	};

public:
	virtual void reset();
	virtual DBError* get_error();
	virtual void set_error( void* data, char* sql, char* method, int line );
	virtual DBStatement* get_statement();

	virtual int connect();
	virtual int reconnect();
	virtual int isActive();
	virtual int disconnect();
	virtual bool setTimeout( size_t timeout );

	virtual int get_table_desc( void* handle, char* table_name, DBTableDescription& desc );

	MYSQL* getSession(){ return &mysql_; }

	int set_char( char* char_set );

	MySQL_DBSession( DBAccount& account, int time_out );
	virtual ~MySQL_DBSession();

	int test();
	int test2();
	int test3();	
	int test_mysql();

protected:

private:	
//	int set_char( char* char_set );
	int set_autocommit( int value );
	int commit();
	int rollback();

	bool check_account();	
	
	MYSQL mysql_;
	int time_out_;	
	MySQL_DBStatement* stmt_;
	MySQL_DBError error_;
};
